﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VisionApp.Startup.Helper;
using VisionApp.Startup.Services;
using VisionApp.Startup.ViewModels;

namespace VisionApp.Startup.Views;

/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow 
{
    private MainWindowViewModel? viewModel => DataContext as MainWindowViewModel;
    public MainWindow()
    {
        InitializeComponent();
        //((App)Application.Current).UpdateTheme(HandyControl.Themes.ApplicationTheme.Dark);
    }

    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        ToggleSideBar.IsChecked = true;
        ToggleSideBar_Click(ToggleSideBar, new RoutedEventArgs());
    }

    private void ToggleSideBar_Click(object sender, RoutedEventArgs e)
    {
        var toggleButton = sender as ToggleButton;
        var sidebarWidth = SidebarColumn.ActualWidth;

        GridLengthAnimation animation;
        if (toggleButton?.IsChecked == true)
        {
            //收起侧边栏
            animation = new GridLengthAnimation
            {
                From = new GridLength(sidebarWidth),
                To = new GridLength(50),
                Duration = new Duration(TimeSpan.FromMilliseconds(200))
            };
        }
        else
        {
            //展开侧边栏
            animation = new GridLengthAnimation
            {
                From = new GridLength(sidebarWidth),
                To = new GridLength(200),
                Duration = new Duration(TimeSpan.FromMilliseconds(200))
            };
        }
        SidebarColumn.BeginAnimation(ColumnDefinition.WidthProperty, animation);
    }
}